unit APubReport;

interface

uses
  AData,

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter, Menus,
  cxLookAndFeelPainters, 
  cxEdit, DB, cxDBData, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, cxImage, StdCtrls, cxButtons, cxLabel,
  cxContainer, cxGroupBox, ComCtrls, frxClass, frxDBSet, DBAccess,
  MyAccess, MemDS, DBCtrls, cxCheckBox, cxStyles, cxCustomData, cxGraphics,
  cxFilter, cxData, cxDataStorage;

type
  TAPubReportForm = class(TForm)
    StatusBar1: TStatusBar;
    cxGroupBox1: TcxGroupBox;
    cxLabel1: TcxLabel;
    cxButton1: TcxButton;
    cxButton2: TcxButton;
    cxImage1: TcxImage;
    cxGridDBTV: TcxGridDBTableView;
    cxGridReportLevel1: TcxGridLevel;
    cxGridReport: TcxGrid;
    frxDBDataSet: TfrxDBDataset;
    Qreport: TMyQuery;
    dsReport: TMyDataSource;
    cxGridDBTVreport_id: TcxGridDBColumn;
    cxGridDBTVreport_desc: TcxGridDBColumn;

    Qreportmenu_name: TStringField;
    Qreportreport_id: TStringField;
    Qreportreport_desc: TStringField;
    Qreportreport_link: TStringField;
    Qreportreport_file: TBlobField;
    Qreportcreate_user: TStringField;
    Qreportcreate_date: TDateTimeField;
    Qreportupd_user: TStringField;
    Qreportupd_date: TDateTimeField;
    Qreportreport_elect: TLargeintField;
    cxGridDBTVreport_elect: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxGridDBTVCellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure QreportBeforePost(DataSet: TDataSet);
    procedure QreportAfterInsert(DataSet: TDataSet);
  private
    FEdited: boolean;
    FMenuName: string;
    FReportDesc: string;
  public
    { Public declarations }
    property Edited: boolean read FEdited write FEdited;
    property MenuName: string read FMenuName write FMenuName;
    property ReportDesc: string read FReportDesc write FReportDesc;
  end;

var
  APubReportForm: TAPubReportForm;

implementation
uses APubUnit;
{$R *.dfm}

procedure TAPubReportForm.FormCreate(Sender: TObject);
begin
  Self.BorderStyle := bsDialog;
end;

procedure TAPubReportForm.FormShow(Sender: TObject);
begin
//  Qreport.Close;
//  Qreport.Params.ParamByName('menu_nameValue').Value := ''+FMenuName+'';
 // Qreport.Open;
// where menu_name = :menu_nameValue
end;

procedure TAPubReportForm.cxGridDBTVCellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  Self.ModalResult := mrOk;
end;

procedure TAPubReportForm.QreportBeforePost(DataSet: TDataSet);
begin
  if Qreport.State in [dsInsert] then
  begin
  DataSet.FieldByName('create_user').Value := ShareInfo.OperatorName;
  DataSet.FieldByName('create_date').Value := Now;
  end else
  if Qreport.State in [dsedit] then
  begin
  DataSet.FieldByName('upd_user').Value := ShareInfo.OperatorName;
  DataSet.FieldByName('upd_date').Value := Now;
  end;
end;

procedure TAPubReportForm.QreportAfterInsert(DataSet: TDataSet);
begin
  if Qreport.State in [dsInsert] then
  begin
  DataSet.FieldByName('menu_name').Value := FMenuName;
  DataSet.FieldByName('report_id').Value := 2;
  end;
end;

end.

